//
//  myView.m
//  DJS
//
//  Created by mac on 2017/12/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "myView.h"
#import "tiXianViewController.h"
#import "PersonalInformationViewController.h"
#import "newsViewController.h"
#import "sheZhiViewController.h"
#import "fanKuiViewController.h"
#import "MyEvaluationViewController.h"
#import "CollectionViewController.h"
#import "BecomeExpertViewController.h"
#import "BangDing3ViewController.h"
#import "bangDingViewController.h"
#import "BalancePaymentsViewController.h"
#import "BalancePayments2ViewController.h"
#import "DownloadViewController.h"
@implementation myView

-(void)creatView{
    self.backgroundColor=_LightGrey;
    
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    _scrollView.scrollsToTop =NO;
    
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    _scrollView.contentSize = CGSizeMake(0,800);
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.viewController.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    UIImageView *beiJing=[UIImageView new];
    [_scrollView addSubview:beiJing];
    [beiJing mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.width.mas_equalTo(_mainW);
        make.height.mas_equalTo(230);
    }];
    beiJing.image=[UIImage imageNamed:@"个人中心背景"];
    
    [self creatTopView];
    
    UIView *centerView=[UIView new];
    [_scrollView addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.width.mas_equalTo(_mainW-10);
        make.top.mas_equalTo(beiJing.mas_bottom).mas_equalTo(50);
        make.height.mas_equalTo(250);
    }];
    centerView.backgroundColor=[UIColor whiteColor];
    centerView.layer.masksToBounds=YES;
    centerView.layer.cornerRadius=5;
    [self creatCenterView:centerView];
    
    UIView *bottomView=[UIView new];
    [_scrollView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.width.mas_equalTo(_mainW-10);
        make.top.mas_equalTo(centerView.mas_bottom).mas_equalTo(10);
        make.height.mas_equalTo(150);
    }];
    bottomView.backgroundColor=[UIColor whiteColor];
    bottomView.layer.masksToBounds=YES;
    bottomView.layer.cornerRadius=5;
    [self creatBottomView:bottomView];

}
-(void)creatTopView{
    
    UIView *topView=[UIView new];
    [_scrollView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(_mainW-40);
        make.top.mas_equalTo(100);
        make.height.mas_equalTo(170);
    }];
    topView.backgroundColor=[UIColor whiteColor];
    topView.layer.masksToBounds=YES;
    topView.layer.cornerRadius=5;
    
    UIView  *beiJingImage=[UIView new];
    [_scrollView addSubview:beiJingImage];
    [beiJingImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(topView);
        make.width.height.mas_equalTo(80);
        make.top.mas_equalTo(60);
    }];
    beiJingImage.backgroundColor=[UIColor whiteColor];
    beiJingImage.layer.masksToBounds=YES;
    beiJingImage.layer.cornerRadius=40;
    
    
    NSNumber *waiter_check=[_userDic objectForKey:@"waiter_check"];
    
    UIImageView *userIamge=[UIImageView new];
    [_scrollView addSubview:userIamge];
    [userIamge mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(beiJingImage);
        make.width.height.mas_equalTo(78);
    }];
    userIamge.layer.masksToBounds=YES;
    userIamge.layer.cornerRadius=39;
    NSString *wl_practice_photo=[_userDic objectForKey:@"waiter_icon"];
    if ([ZQTools charIsNil:wl_practice_photo]) {
        userIamge.image=[UIImage imageNamed:@"未登录头像"];
    }
    else
    {
        wl_practice_photo=[NSString stringWithFormat:@"%@%@",_addressUrl,wl_practice_photo];
        NSURL *url=[NSURL URLWithString:wl_practice_photo];
        [userIamge sd_setImageWithURL:url];
    }
    
    UIImageView *renZhengImage=[UIImageView new];
    [_scrollView addSubview:renZhengImage];
    [renZhengImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.mas_equalTo(userIamge);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(15);
    }];
    if (waiter_check.integerValue==0||waiter_check.integerValue==2) {
        renZhengImage.image=[UIImage imageNamed:@"未认证"];
    }
    else{
        renZhengImage.image=[UIImage imageNamed:@"已认证"];
    }
    
    userIamge.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToLogin:)];
    [userIamge addGestureRecognizer:tapGesture];
    
    UILabel *userLabel=[UILabel new];
    [topView addSubview:userLabel];
    [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(beiJingImage.mas_bottom).mas_equalTo(10);
    }];
    if (_userDic==nil) {
        userLabel.text=@"登录/注册";
    }
    else{
        NSString *waiter_name=[_userDic objectForKey:@"waiter_name"];
        if ([ZQTools charIsNil:waiter_name]) {
            waiter_name=@"";
        }
        userLabel.text=waiter_name;
    }
    userLabel.textColor=ColorWithRGB(49, 49, 49);
    userLabel.font=[UIFont systemFontOfSize:20];
    userLabel.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToLogin:)];
    [userLabel addGestureRecognizer:tapGesture2];

    
    UIView *yuEView=[UIView new];
    [topView addSubview:yuEView];
    [yuEView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.mas_equalTo(0);
        make.width.mas_equalTo((_mainW-40)/3);
        make.height.mas_equalTo(60);
    }];
    
    UILabel *numLAbel=[UILabel new];
    [yuEView addSubview:numLAbel];
    [numLAbel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(-15);
    }];
    NSNumber *waiter_balance=[_userDic objectForKey:@"waiter_balance"];
    if (waiter_balance==nil) {
        waiter_balance=@0;
    }
    
    numLAbel.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture13 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan:)];
    [numLAbel addGestureRecognizer:tapGesture13];
    
    numLAbel.text=[NSString stringWithFormat:@"%@",waiter_balance];
    numLAbel.textColor=ColorWithRGB(149, 149, 149);
    numLAbel.font=[UIFont systemFontOfSize:15];
    
    UILabel *yuELabel=[UILabel new];
    [yuEView addSubview:yuELabel];
    [yuELabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(15);
    }];
    yuELabel.text=@"余额(元)";
    yuELabel.font=[UIFont systemFontOfSize:15];
    yuELabel.textColor=ColorWithRGB(149, 149, 149);
    yuELabel.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture12 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan:)];
    [yuEView addGestureRecognizer:tapGesture12];
    
    UIView *shouYiView=[UIView new];
    [topView addSubview:shouYiView];
    [shouYiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(yuEView.mas_right);
        make.width.mas_equalTo((_mainW-40)/3);
        make.height.mas_equalTo(60);
    }];
    UITapGestureRecognizer *tapGesture14 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan2:)];
    [shouYiView addGestureRecognizer:tapGesture14];
    
    UILabel *numLAbel2=[UILabel new];
    [shouYiView addSubview:numLAbel2];
    [numLAbel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(-15);
    }];
    NSNumber *waiter_line_income=[_userDic objectForKey:@"waiter_line_income"];
    if (waiter_line_income==nil) {
        waiter_line_income=@0;
    }
    
    numLAbel2.text=[NSString stringWithFormat:@"%@",waiter_line_income];
    numLAbel2.textColor=ColorWithRGB(149, 149, 149);
    numLAbel2.font=[UIFont systemFontOfSize:15];
    
    UILabel *shouYiELabel=[UILabel new];
    [shouYiView addSubview:shouYiELabel];
    [shouYiELabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(15);
    }];
    shouYiELabel.text=@"线下收益(元)";
    shouYiELabel.font=[UIFont systemFontOfSize:15];
    shouYiELabel.textColor=ColorWithRGB(149, 149, 149);
    
    
    UIView *tiXianView=[UIView new];
    [topView addSubview:tiXianView];
    [tiXianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(shouYiView.mas_right);
        make.width.mas_equalTo((_mainW-40)/3);
        make.height.mas_equalTo(60);
    }];
    
    UIImageView *tiXianImga=[UIImageView new];
    [tiXianView addSubview:tiXianImga];
    [tiXianImga mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(-15);
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(18);
    }];
    tiXianImga.image=[UIImage imageNamed:@"提现"];
    tiXianView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tiXianTp = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToTiXian:)];
    [tiXianView addGestureRecognizer:tiXianTp];
    
    UILabel *tiXianELabel=[UILabel new];
    [tiXianView addSubview:tiXianELabel];
    [tiXianELabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(15);
    }];
    tiXianELabel.text=@"提现";
    tiXianELabel.font=[UIFont systemFontOfSize:15];
    tiXianELabel.textColor=ColorWithRGB(149, 149, 149);
    tiXianELabel.userInteractionEnabled=YES;
    UITapGestureRecognizer *tiXianTp2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToTiXian:)];
    [tiXianELabel addGestureRecognizer:tiXianTp2];
}
-(void)creatCenterView:(UIView *)view{
    NSArray *nameArr=[NSArray arrayWithObjects:@"我的评价",@"我的收藏",@"成为专家",@"绑定银行卡",@"我的下载", nil];
    for (int i=0; i<5; i++) {
        UIView *beiJingView=[UIView new];
        [view addSubview:beiJingView];
        [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(50);
            make.top.mas_equalTo(50*i);
        }];
        beiJingView.tag=i;
        UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToGongNei:)];
        [beiJingView addGestureRecognizer:tapGesture2];
        
        UIImageView *imageView=[UIImageView new];
        [beiJingView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.centerY.mas_equalTo(0);
            make.width.height.mas_equalTo(25);
        }];
        imageView.image=[UIImage imageNamed:nameArr[i]];
        
        UILabel *label=[UILabel new];
        [beiJingView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(imageView.mas_right).mas_equalTo(15);
            make.centerY.mas_equalTo(0);
        }];
        label.text=nameArr[i];
        label.textColor=ColorWithRGB(49, 49, 49);
        label.font=[UIFont systemFontOfSize:16];
        
        UIImageView *jianTou=[UIImageView new];
        [beiJingView addSubview:jianTou];
        [jianTou mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-10);
            make.centerY.mas_equalTo(0);
            make.width.mas_equalTo(10);
            make.height.mas_equalTo(15);
        }];
        jianTou.image=[UIImage imageNamed:@"iconfont-fanhui-拷贝-3"];
    }
    
}
-(void)creatBottomView:(UIView *)view{
    NSArray *nameArr=[NSArray arrayWithObjects:@"消息",@"设置",@"意见反馈", nil];
    for (int i=0; i<3; i++) {
        UIView *beiJingView=[UIView new];
        [view addSubview:beiJingView];
        [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(50);
            make.top.mas_equalTo(50*i);
        }];
        beiJingView.tag=i;
        UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToXiTong:)];
        [beiJingView addGestureRecognizer:tapGesture2];
        
        view.userInteractionEnabled=YES;
        UITapGestureRecognizer *tiXianTp2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToGongNeng:)];
        [view addGestureRecognizer:tiXianTp2];
        UIImageView *imageView=[UIImageView new];
        [beiJingView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.centerY.mas_equalTo(0);
            make.width.height.mas_equalTo(25);
        }];
        imageView.image=[UIImage imageNamed:nameArr[i]];
        
        UILabel *label=[UILabel new];
        [beiJingView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(imageView.mas_right).mas_equalTo(15);
            make.centerY.mas_equalTo(0);
        }];
        label.text=nameArr[i];
        label.textColor=ColorWithRGB(49, 49, 49);
        label.font=[UIFont systemFontOfSize:16];
        
        UIImageView *jianTou=[UIImageView new];
        [beiJingView addSubview:jianTou];
        [jianTou mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-10);
            make.centerY.mas_equalTo(0);
            make.width.mas_equalTo(10);
            make.height.mas_equalTo(15);
        }];
        jianTou.image=[UIImage imageNamed:@"iconfont-fanhui-拷贝-3"];
    }
    
}

-(void)pushToLogin:(UITapGestureRecognizer *)tap{
    if (_userDic.count==0) {
        _loginWithVc(self.viewController);
    }
    else{
        PersonalInformationViewController *person=[[PersonalInformationViewController  alloc] init];
        person.dic=_userDic;
        [ZQTools pushNextViewController:self.viewController andRootController:person];
        
    }
    
}
-(void)pushToGongNei:(UITapGestureRecognizer *)tap{
    
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
  
    NSNumber *waiter_check=[_userDic objectForKey:@"waiter_check"];
    

    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }
    if (tap.view.tag==0) {
        MyEvaluationViewController *geRen=[[MyEvaluationViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        
    }  if (tap.view.tag==1) {
        CollectionViewController *geRen=[[CollectionViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        
    }if (tap.view.tag==2) {
        if (waiter_check.integerValue==0||waiter_check.integerValue==2) {
            [ZQTools svpInfo:@"请先填写个人资料进行认证"];
            return;
        }
      
        
        NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
        NSString *token=[userDic objectForKey:@"token"];
        NSNumber *waiter_id1=[userDic objectForKey:@"waiter_id"];
        NSString *waiter_id=[NSString stringWithFormat:@"%@",waiter_id1];
        
        NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"waiter_role",@"1",@"user_role",token,@"token",waiter_id,@"waiter_id", nil];
        [ZQTools AFNPostDataUrl:@"waiter/waiter/apply_info" Dict:dic andTableView:nil andViewController:self.viewController andSuccessBlock:^(id responseObject) {
            if (responseObject==nil) {
                BecomeExpertViewController *geRen=[[BecomeExpertViewController alloc] init];
                geRen.dic=nil;
                [ZQTools pushNextViewController:self.viewController andRootController:geRen];
            }else{
                NSNumber *cr_check=[responseObject objectForKey:@"cr_check"];
                if (cr_check.integerValue==0||cr_check.integerValue==2) {
                    BecomeExpertViewController *geRen=[[BecomeExpertViewController alloc] init];
                    geRen.dic=responseObject;
                    [ZQTools pushNextViewController:self.viewController andRootController:geRen];
                }
                else{
                    [ZQTools svpInfo:@"你成为专家"];
                }
            }
        } anderrorBlock:nil];
        
        
    }
    
    if (tap.view.tag==3) {
        if (waiter_check.integerValue==0||waiter_check.integerValue==2) {
            [ZQTools svpInfo:@"请先填写个人资料进行认证"];
            return;
        }
        NSString *wl_bank_number=[_userDic objectForKey:@"wl_bank_number"];
        if ([ZQTools charIsNil:wl_bank_number]) {
            bangDingViewController *geRen=[[bangDingViewController alloc] init];
            [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        }
        else{
            BangDing3ViewController *geRen=[[BangDing3ViewController alloc] init];
            [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        }
        
    }
    if (tap.view.tag==4) {
        DownloadViewController *geRen=[[DownloadViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:geRen];

    }
    
}

-(void)pushToXiTong:(UITapGestureRecognizer *)tap{
    
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }
    if (tap.view.tag==0) {
        NewsViewController *geRen=[[NewsViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        
    }  if (tap.view.tag==1) {
        sheZhiViewController *geRen=[[sheZhiViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        
    }if (tap.view.tag==2) {
        fanKuiViewController *geRen=[[fanKuiViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:geRen];
        
    }
    
}

-(void)chanKan:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    BalancePaymentsViewController *af=[[BalancePaymentsViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:af];
}


-(void)chanKan2:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }
    BalancePayments2ViewController *af=[[BalancePayments2ViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:af];
}

-(void)pushToTiXian:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    tiXianViewController *tiXian=[[tiXianViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:tiXian];
}
-(void)pushToGongNeng:(UITapGestureRecognizer *)tap{
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    [defaultManager removeItemAtPath:_userModelFile error:nil];
//    [self.viewContrlloer.navigationController popToRootViewControllerAnimated:YES];
}
@end
